<template>
  <div>
    <el-container>
      <el-main>
        <kendoForm
          :kendo-form-items="kendoFormItems"
          :kendo-form="kendoForm"
          :kendo-params-value="kendoParamsValue"
        />
      </el-main>
    </el-container>
    <el-container style="padding-left:5px">
      <el-main>
        <KendoGridCmpt
          ref="DictGrid"
          :table-grid-option="tableGridOption"
          :table-grid-data-source-option="tableGridDataSourceOption"
          :table-grid-toolbar="tableGridToolbar"
          @persistSelection="selectDataItems"
        />
      </el-main>
    </el-container>
  </div>

</template>

<script>
  import kendoForm from '@/Views/components/kendo-vue-component/kendoForm/index.vue'
  // import kendoGrid from '@/Views/components/kendo-vue-component/kendoGrid/index.vue'
  export default {
    name: 'DictManage',
    components: {
      kendoForm
    },
    data() {
      return {
        /* Form*/
        kendoFormItems: [
          {
            name: 'dictTp',
            label: '字典类型',
            paramName: 'dictTp',
            controlType: 'input'
          },
          {
            name: 'dictName',
            label: '字典名称',
            paramName: 'dictName',
            controlType: 'input'
          }
        ],
        kendoForm: {
          ref: 'prjForm',
          valid: 'valid',
          buttons: [
            {
              name: '查询', // 按钮内容
              class: 'k-primary', // 按钮样式
              icon: 'search',
              click: this.search
            },
            {
              name: '重置', // 按钮内容
              icon: 'reset-sm', // 按钮样式
              click: this.reset
            }
          ]
        },
        kendoParamsValue: {
          dictTp: '',
          dictName: ''
        },
        tableGridToolbar: [
          {
            text: '新增',
            class: 'k-primary',
            icon: 'upload',
            option: {
              /** @Description
                 模式 ：dataReq:数据操作，请求后台处理 dataView 数据操作，请求前端页面渲染视图
                 model: 'dataReq',
                 如果是dataReq 那么必须要有 :{
                  transportRequestUrl: ''(请求地址)
                  parameterMap (请求参数)
                 }
              */
              model: 'dataView',
              componentUrl: '/sysmanage/dictmanage/operate/add.vue',
              dialogTitle: '新增字典参数',
              parameterMap: {}
            },
            /**
             * @description 操作类型 add (新增) update(修改) del(删除) view(查看)
            */
            operatorType: 'add'
          },
          {
            text: '修改',
            class: 'k-primary',
            icon: 'edit',
            option: {
              /** @Description
                 模式 ：dataReq:数据操作，请求后台处理 dataView 数据操作，请求前端页面渲染视图
                 model: 'dataReq',
                 如果是dataReq 那么必须要有 :{
                  transportRequestUrl: ''(请求地址)
                  parameterMap (请求参数)
                 }
              */
              model: 'dataView',
              componentUrl: '/sysmanage/dictmanage/operate/add.vue',
              dialogTitle: '修改字典参数',
              parameterMap: {}
            },
            /**
             * @description 操作类型 add (新增) edit(修改) del(删除) view(查看)
            */
            operatorType: 'edit'
          }
        ],
        // maintain 字典数据列表
        tableGridOption: {
          ref: 'dictOptGrid',
          dataSourceRef: 'dictDataSource',
          remoteData: true,
          sortable: true,
          reorderable: true,
          resizable: true,
          pageable: true,
          selectSingle: false,
          selectMultiple: true,
          toolbar: ['excel'],
          excel: {
            fileName: '字典数据表',
            allPages: true
          },
          columns: [
            {
              field: 'dictTp',
              title: '字典类型',
              width: 180
            },
            {
              field: 'dictTpNm',
              title: '字典类型名称',
              width: 220
            },
            {
              field: 'dictKey',
              title: '字典键',
              width: 220
            },
            {
              field: 'dictVal',
              title: '字典值',
              width: 220
            },
            {
              field: 'dictValNm',
              title: '字典值名称',
              width: 150
            },

            {
              field: 'parentDictVal',
              title: '父字典值',
              width: 100
            },
            {
              field: 'dictGroup',
              title: '字典组',
              width: 180
            },
            {
              field: 'dictStatus',
              title: '字典状态',
              dictData: 'DICT_STATUS_CD',
              width: 80
            }
          ]
        },
        tableGridDataSourceOption: {
          ref: 'dictDataSource',
          type: 'json',
          pageSize: 10,
          transportReadUrl: '/service/sysMng/dict/findDictPage',
          serverPaging: true,
          dict: ['DICT_STATUS_CD'],
          params: {},
          schema: {
            model: {
              id: 'id',
              fields: {
                dictTp: { editable: false, type: 'string' },
                dictTpNm: { editable: false, type: 'string' },
                dictKey: { editable: false, type: 'string' },
                dictVal: { editable: false, type: 'string' },
                dictValNm: { editable: false, type: 'string' },
                parentDictVal: { editable: false, type: 'string' },
                dictGroup: { editable: false, type: 'string' },
                dictStatus: { editable: false, type: 'string' }
              }
            },
            data: function(response) {
              return response.data.list
            },
            total: function(response) {
              return response.data.total
            }
          }
        },
        selectData: []
      }
    },
    mounted() {

    },
    methods: {
      /* grid*/
      selectDataItems(res) {
        this.selectData = res
      },
      search(paramVal, validator) {
        this.tableGridDataSourceOption.params = Object.assign(this.tableGridDataSourceOption.params, this.deepCopy(paramVal))
        this.tableGridDataSourceOption.params.pageNum = 1
        this.$refs['DictGrid'].transportReadGrid()
      },
      reset(paramVal) {
        Object.keys(paramVal).forEach(key => {
          if (Array.isArray(paramVal[key])) {
            this.kendoParamsValue[key] = []
          } else {
            this.kendoParamsValue[key] = ''
          }
        })
        this.$refs['DictGrid'].transportReadGrid()
      }
    }
  }
</script>

<style>

</style>
